import Vue from 'vue'
import Router from 'vue-router'

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

Vue.use(Router)

import Main from '@/view/main'

/**
 * iview-admin中meta除了原生参数外可配置的参数:
 * meta: {
 *  hideInMenu: (false) 设为true后在左侧菜单不会显示该页面选项
 *  notCache: (false) 设为true后页面不会缓存
 *  access: (null) 可访问该页面的权限数组，当前路由设置的权限会影响子路由
 *  icon: (-) 该页面在左侧菜单、面包屑和标签导航处显示的图标，如果是自定义图标，需要在图标名称前加下划线'_'
 * }
 */

export default [{
        path: '/admin-view/login',
        name: 'login',
        meta: {
            title: '登录',
            hideInMenu: true,
        },
        component: () =>
            import ('@/view/login/login.vue'),
    },
    {
        path: '/admin-view/system_manage',
        name: 'system_manage',
        component: Main,
        meta: {
            access: ['system-setting'],
            title: '系统管理'
        },
        children: [
            {
                path: 'system-setting',
                name: 'system-setting',
                meta: {
                    access: ['system-setting'],
                    title: '系统配置',
                    notCache: true,
                },
                component: () =>
                    import ('@/view/system/setting')
            },
        ]
    },
    {
        path: '/admin-view/banner_manage',
        name: 'banner_manage',
        component: Main,
        meta: {
            access: ['banner-list'],
            title: '轮播图管理'
        },
        children: [{
                path: 'banner-list',
                name: 'banner-list',
                meta: {
                    access: ['banner-list'],
                    title: '轮播图管理',
                    notCache: true,
                },
                component: () =>
                    import ('@/view/banner_manage/index')
            }
        ]
    },
    {
        path: '/admin-view/good_manage',
        name: 'good_manage',
        component: Main,
        meta: {
            access: ['good-cate-list', 'good-list'],
            title: '商品管理'
        },
        children: [
            {
                path: 'good-cate-list',
                name: 'good-cate-list',
                meta: {
                    access: ['good-cate-list'],
                    title: '商品类别',
                    notCache: true,
                },
                component: () =>
                    import ('@/view/good/good_cate_list')
            },
            {
                path: 'good-list',
                name: 'good-list',
                meta: {
                    access: ['good-list'],
                    title: '商品列表',
                    notCache: true,
                },
                component: () =>
                    import ('@/view/good/good_list')
            },
            {
                path: 'good-edit/:id',
                name: 'good-edit',
                meta: {
                    title: '商品信息',
                    hideInMenu: true,
                    notCache: true,
                },
                component: () =>
                    import ('@/view/good/good_detail.vue'),
            }
        ]
    },
    {
        path: '/admin-view/member_manage',
        name: 'member_manage',
        component: Main,
        meta: {
            access: ['member-list'],
            title: '会员管理'
        },
        children: [{
            path: 'member-list',
            name: 'member-list',
            meta: {
                access: ['member-list'],
                title: '会员管理',
                notCache: true,
            },
            component: () =>
                import ('@/view/member/index')
        }]
    },
    {
        path: '/admin-view/order_manager',
        name: 'order_manager',
        component: Main,
        meta: {
            access: ['money-info', 'order-list', 'order-refund'],
            title: '财务管理'
        },
        children: [{
                path: 'money-info',
                name: 'money-info',
                meta: {
                    access: ['money-info'],
                    title: '资产信息',
                    notCache: true,
                },
                component: () =>
                    import ('@/view/order/money')
            },
            {
                path: 'order-list',
                name: 'order-list',
                meta: {
                    access: ['order-list'],
                    title: '订单列表',
                    notCache: true,
                },
                component: () =>
                    import ('@/view/order/list')
            },
            {
                path: 'order-refund',
                name: 'order-refund',
                meta: {
                    access: ['order-refund'],
                    title: '退款列表',
                    notCache: true,
                },
                component: () =>
                    import ('@/view/order/refund')
            }
        ]
    },
    {
        path: '/admin-view/user_manager',
        name: 'user_manager',
        meta: {
            access: ['role-list', 'user-list', 'privilege-list'],
            title: '后台用户管理',
        },
        component: Main,
        children: [{
                path: 'privilege-list',
                name: 'privilege-list',
                meta: {
                    title: '权限管理',
                    //hideInMenu: true,
                },
                component: () =>
                    import ('@/view/user/privilege_list'),
            },
            {
                path: 'role-list',
                name: 'role-list',
                meta: {
                    access: ['role-list'],
                    title: '角色管理',
                },
                component: () =>
                    import ('@/view/user/role_list'),
            },
            {
                path: 'add_role',
                name: 'add_role',
                meta: {
                    title: '创建角色',
                    notCache: true,
                    hideInMenu: true,
                },
                component: () =>
                    import ('@/view/user/add_role'),
            },
            {
                path: 'edit_role/:name',
                name: 'edit_role',
                meta: {
                    title: '编辑角色',
                    notCache: true,
                    hideInMenu: true
                },
                component: () =>
                    import ('@/view/user/edit_role'),
            },
            {
                path: 'user-list',
                name: 'user-list',
                meta: {
                    access: ['user-list'],
                    title: '账号管理',
                    notCache: true,
                    type: 10,
                    is_vest: -1
                },
                component: () =>
                    import ('@/view/user/list.vue'),
            },
        ],
    },
    {
        path: '/argu',
        name: 'argu',
        meta: {
            hideInMenu: true,
        },
        component: Main,
        children: [{
                path: 'params/:id',
                name: 'params',
                meta: {
                    title: '动态路由',
                    notCache: true,
                },
                component: () =>
                    import ('@/view/argu-page/params.vue'),
            },
            {
                path: 'query',
                name: 'query',
                meta: {
                    title: '带参路由',
                    notCache: true,
                },
                component: () =>
                    import ('@/view/argu-page/query.vue'),
            },
        ],
    },
    {
        path: '/401',
        name: 'error_401',
        meta: {
            hideInMenu: true,
        },
        component: () =>
            import ('@/view/error-page/401.vue'),
    },
    {
        path: '/500',
        name: 'error_500',
        meta: {
            hideInMenu: true,
        },
        component: () =>
            import ('@/view/error-page/500.vue'),
    },
    {
        path: '*',
        name: 'error_404',
        meta: {
            hideInMenu: true,
        },
        component: () =>
            import ('@/view/error-page/404.vue'),
    },
]